package com.infore.metadata.core.model;

import lombok.Data;

/**
 * 基础数据类型
 *
 * @author ：lijh
 * @date 创建时间： 2022/12/19 9:22
 */
@Data
public class PrimitiveTypeWrapper extends FullyQualifiedJavaType {

    /**
     * 调用的方法，比如：booleanValue() charValue() 等
     */
    private String toPrimitiveMethod;






    /**
     * 布尔类型
     */
    private static PrimitiveTypeWrapper booleanInstance;
    /**
     * 比特类型
     */
    private static PrimitiveTypeWrapper byteInstance;
    /**
     * 字符类型
     */
    private static PrimitiveTypeWrapper characterInstance;
    /**
     * 双精度
     */
    private static PrimitiveTypeWrapper doubleInstance;
    /**
     * 浮点
     */
    private static PrimitiveTypeWrapper floatInstance;
    /**
     * 整型
     */
    private static PrimitiveTypeWrapper integerInstance;
    /**
     * 长整型
     */
    private static PrimitiveTypeWrapper longInstance;
    /**
     * 短整型
     */
    private static PrimitiveTypeWrapper shortInstance;



    /**
     * 构造器
     * @param fullyQualifiedName 包装器类型的完全限定名
     * @param toPrimitiveMethod  返回包装原语的方法
     */
    private PrimitiveTypeWrapper(String fullyQualifiedName, String toPrimitiveMethod) {
        super(fullyQualifiedName);
        this.toPrimitiveMethod = toPrimitiveMethod;
    }

    /**
     * 获取布尔类型实例
     * @return
     */
    public static PrimitiveTypeWrapper getBooleanInstance() {
        if (booleanInstance == null) {
            booleanInstance = new PrimitiveTypeWrapper("java.lang.Boolean", "booleanValue()");
        }

        return booleanInstance;
    }

    /**
     * 获取比特类型实例
     * @return
     */
    public static PrimitiveTypeWrapper getByteInstance() {
        if (byteInstance == null) {
            byteInstance = new PrimitiveTypeWrapper("java.lang.Byte", "byteValue()");
        }

        return byteInstance;
    }

    /**
     * 获取字符类型实例
     * @return
     */
    public static PrimitiveTypeWrapper getCharacterInstance() {
        if (characterInstance == null) {
            characterInstance = new PrimitiveTypeWrapper("java.lang.Character", "charValue()");
        }

        return characterInstance;
    }

    /**
     * 获取双精度浮点型实例
     * @return
     */
    public static PrimitiveTypeWrapper getDoubleInstance() {
        if (doubleInstance == null) {
            doubleInstance = new PrimitiveTypeWrapper("java.lang.Double", "doubleValue()");
        }

        return doubleInstance;
    }

    /**
     * 获取浮点型实例
     * @return
     */
    public static PrimitiveTypeWrapper getFloatInstance() {
        if (floatInstance == null) {
            floatInstance = new PrimitiveTypeWrapper("java.lang.Float", "floatValue()");
        }

        return floatInstance;
    }

    /**
     * 获取整型实例
     * @return
     */
    public static PrimitiveTypeWrapper getIntegerInstance() {
        if (integerInstance == null) {
            integerInstance = new PrimitiveTypeWrapper("java.lang.Integer", "intValue()");
        }

        return integerInstance;
    }

    /**
     * 获取长整型实例
     * @return
     */
    public static PrimitiveTypeWrapper getLongInstance() {
        if (longInstance == null) {
            longInstance = new PrimitiveTypeWrapper("java.lang.Long", "longValue()");
        }

        return longInstance;
    }

    /**
     * 获取短型实例
     * @return
     */
    public static PrimitiveTypeWrapper getShortInstance() {
        if (shortInstance == null) {
            shortInstance = new PrimitiveTypeWrapper("java.lang.Short", "shortValue()");
        }

        return shortInstance;
    }

    public String getToPrimitiveMethod() {
        return toPrimitiveMethod;
    }

}
